<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * 返回jsondata的通用函数
 * [
        ['id'=>1,'name'=>'yxg','rows'=>2,'data_length'=>15,'create_time'=>'2018-10-32'],
        ['id'=>2,'name'=>'lr','rows'=>3,'data_length'=>15,'create_time'=>'2018-10-32']
    ];
 */
function jsonData($code,$count,$data,$msg=''){
    $re['code']=intval($code);
    $re['msg']=$msg;
    $re['count']=$count;
    $re['data']=$data;
    return json_encode($re,JSON_UNESCAPED_UNICODE);
    // return json($re);
}
/**
 * 全局变量
 * @param null   $name  变量名
 * @param string $value 变量值
 * @return array|mixed|null|string
 */
if(!function_exists('v')){
    function v($name = null, $value = '[null]')
    {
        static $vars = [];
        if (is_null($name)) {
            return $vars;
        } else if ($value == '[null]') {
            //取变量
            $tmp = $vars;
            foreach (explode('.', $name) as $d) {
                if (isset($tmp[$d])) {
                    $tmp = $tmp[$d];
                } else {
                    return null;
                }
            }
            return $tmp;
        } else {
            //设置
            $tmp = &$vars;
            foreach (explode('.', $name) as $d) {
                if ( ! isset($tmp[$d])) {
                    $tmp[$d] = [];
                }
                $tmp = &$tmp[$d];
            }
            return $tmp = $value;
        }
    }
}